package com.xl.generator.common;

import org.springframework.stereotype.Component;

/**
 * @author XGJ
 * @apiNote
 * @date 2022/10/6 21:51
 */
@Component
public  class ActionResultService {

    /**
     * 封装统一前台页面返回
     *
     * @param success        success
     * @param result         result
     * @param code           code
     * @param message        message
     * @param attachedResult attachedResult
     * @return
     * @author liugang
     * @since 2017/08/07 8:47
     */

    public static <R, A> ActionResult<R, A> callBackResult(boolean success, String code, String message, R result, A attachedResult) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(success);
        actionResult.getStatus().setMessage(message);
        actionResult.getStatus().setCode(code);
        // Result
        actionResult.setResult(result);
        // AttachedResult
        actionResult.setAttached(attachedResult);
        return actionResult;
    }
    public static  <R, A> ActionResult<R, A> callBackResultOK(R result, A attachedResult) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(true);
        actionResult.getStatus().setMessage("成功");
        actionResult.getStatus().setCode("0");
        // Result
        actionResult.setResult(result);
        // AttachedResult
        actionResult.setAttached(attachedResult);
        return actionResult;
    }
    public static  <R, A> ActionResult<R, A> callBackResultOK(String message,R result, A attachedResult) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(true);
        actionResult.getStatus().setMessage(message);
        actionResult.getStatus().setCode("0");
        // Result
        actionResult.setResult(result);
        // AttachedResult
        actionResult.setAttached(attachedResult);
        return actionResult;
    }
    public static  <R, A> ActionResult<R, A> callBackResultOK(String message,R result) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(true);
        actionResult.getStatus().setMessage(message);
        actionResult.getStatus().setCode("0");
        // Result
        actionResult.setResult(result);
        // AttachedResult
        actionResult.setAttached(null);
        return actionResult;
    }
    public static <R, A> ActionResult<R, A> callBackResultOK(R result) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(true);
        actionResult.getStatus().setMessage("成功");
        actionResult.getStatus().setCode("0");
        // Result
        actionResult.setResult(result);
        // AttachedResult
        actionResult.setAttached(null);
        return actionResult;
    }
    public static <R, A> ActionResult<R, A> callBackResultFail(String message,A attachedResult) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(false);
        actionResult.getStatus().setMessage(message);
        actionResult.getStatus().setCode("-1");
        // Result
        actionResult.setResult(null);
        // AttachedResult
        actionResult.setAttached(attachedResult);
        return actionResult;
    }
    public static <R, A> ActionResult<R, A> callBackResultFail(A attachedResult) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(false);
        actionResult.getStatus().setMessage("失败");
        actionResult.getStatus().setCode("-1");
        // Result
        actionResult.setResult(null);
        // AttachedResult
        actionResult.setAttached(attachedResult);
        return actionResult;
    }
    public static <R, A> ActionResult<R, A> callBackResultFail(String message) {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(false);
        actionResult.getStatus().setMessage(message);
        actionResult.getStatus().setCode("-1");
        // Result
        actionResult.setResult(null);
        // AttachedResult
        actionResult.setAttached(null);
        return actionResult;
    }
    public static <R, A> ActionResult<R, A> callBackResultFail() {
        ActionResult<R, A> actionResult = new ActionResult<>();
        // StatusResult
        actionResult.getStatus().setSuccess(false);
        actionResult.getStatus().setMessage("失败");
        actionResult.getStatus().setCode("-1");
        // Result
        actionResult.setResult(null);
        // AttachedResult
        actionResult.setAttached(null);
        return actionResult;
    }
    /**
     * 封装统一前台页面返回
     *
     * @param success success
     * @param code    code
     * @param message message
     * @param result  result
     * @return
     * @author liugang
     * @since 2018/12/11 14:24
     */
    public  <R, A> ActionResult<R, A> callBackResult(boolean success, String code, String message, R result) {
        return this.callBackResult(success, code, message, result, null);
    }

    /**
     * 封装统一前台页面返回
     *
     * @param success success
     * @param code    code
     * @param message message
     * @return com.liuchink.chinkframe.mq.common.result.ActionResult
     * @author liugang
     * @since 2018/12/11 14:24
     */
    public <R, A> ActionResult<R, A> callBackResult(boolean success, String code, String message) {
        return this.callBackResult(success, code, message, null, null);
    }

    /**
     * 封装统一前台页面返回
     *
     * @return com.liuchink.chinkframe.standard.admin.base.common.result.ActionResult
     * @author liugang
     * @since 2018/3/15 11:27
     */
    public <R, A> ActionResult<R, A> callBackResult() {
        return this.callBackResult(true, "0", "请求成功", null, null);
    }
}
